const http = require('http')
const fs = require('fs')
const path = require('path')


const app = http.createServer()

app.on('request', (req, res) => {

    const url = req.url

    // const fpath = path.join(__dirname, url)
    let fpath = ''

    if (url === '/') {
        fpath = (path.join(__dirname, './clock/index.html'))
    } else {
        fpath = path.join(__dirname, './clock', url)
    }

    fs.readFile(fpath, 'utf-8', (err, data) => {

        if (err) return res.end('404 Not Fount')

        res.end(data)
    })
})

app.listen(3000, () => {
    console.log('服务器启动于: http://127.0.0.1:3000');
})